--[[
描述 ：票据交易主页面 - BuyBill.lua
作者 ： 焉杉 <5kg.elastic - <3#> /Bazinga/
时间 ： 2016/01/20
]]
HomeView = Class(ViewCtrl,'HomeView');
HomeView.title = '票据交易';
HomeView.id ='HomeView';
HomeView.hideHeadView = false;
HomeView.GalleryArray = {};   -- 轮播图数组
HomeView.rv = nil;            -- rootView

--[[
功能   ： onCreate初始化
参数   ： rootView 根视图
返回   ： 无
]]
function HomeView:onCreate(rootView)

  -- 获取到内容区域的宽高
  local w,h = rootView:getWH();

  self.rv = rootView;

  -- 设置页面背景颜色
  rootView:setColor(UIColor.COLOR_BACKGROUND);

 
  -- 隐藏HeadView右边
  self.headView:setRightHidden(false);
  self.headView:setRightTheme('',UIImage.imageName('system/user_normal.png'),UIImage.imageName('system/user_normal.png'),nil,nil,nil);
  self.headView.right:setXY(AW(280),AH(5));
  self.headView.right:setWH(AW(30),AH(30));

  --点击事件
  self.headView.right.onClick = function()
  if FastDB.LOGIN_TAG=='0' then
  --登录页面
    local next = Login.new();
    self:push(next);
  else
    local alert = UIAlertView.new():init('是否注销','','确定','关闭',self);
    alert.onClickEvent = function(v)
    if v == 1 then
       --清空FastDB
       FastDB.LOGIN_NAME = nil;
       FastDB.LOGIN_PATH = nil;
       FastDB.LOGIN_TAG = '0';
       FastDBOpt.save();
  
      --提示注销成功
      UIHUD:notify('注销成功',2000,self);
      else
      end
     end
    end
  end

  --按钮
  local Button1 = UIButton.new():init(AW(70),AW(70),self,1);
  Button1.bgImage = UIImage.imageName('system/11.png');
  Button1.focusImage = UIImage.imageName('system/12.png');
  Button1.onClick = function()
  local next2 = HomeViewURLquery.new();
   self:push(next2);
 end
  
  rootView:add(Button1, AW(25), AH(20));
  
   local text1 = UILabel.new():init('票据查询',AW(75),AH(20),self);
  text1.fontHeight = AW(14);
  text1.fontColor = 0x000000;
  text1.fontFocusColor = 0xff0000;
  text1.align = 0;
  rootView:add(text1,AW(30),AH(95));


 local Button2 = UIButton.new():init(AW(70),AW(70),self,2);
  Button2.bgImage = UIImage.imageName('system/21.png');
  Button2.focusImage = UIImage.imageName('system/22.png');
  Button2.onClick = function()
  local next3 = ContactUs.new();
   self:push(next3);
 end
  rootView:add(Button2, AW(128), AH(20));
  
   local text2 = UILabel.new():init('我要卖出',AW(75),AH(20),self);
  text2.fontHeight = AW(14);
  text2.fontColor = 0x000000;
  text2.align = 1;
  rootView:add(text2,AW(125),AH(95));
  
  
   local Button3 = UIButton.new():init(AW(70),AW(70),self,3);
  Button3.bgImage = UIImage.imageName('system/31.png');
  Button3.focusImage = UIImage.imageName('system/32.png');
  rootView:add(Button3, AW(230), AH(20));
  
   local text3 = UILabel.new():init('我要购买',AW(75),AH(20),self);
  text3.fontHeight = AW(14);
  text3.fontColor = 0x000000;
  text3.align = 2;
  rootView:add(text3,AW(220),AH(95));


--第二行
local Button4 = UIButton.new():init(AW(70),AW(70),self,4);
  Button4.bgImage = UIImage.imageName('system/41.png');
  Button4.focusImage = UIImage.imageName('system/42.png');
  rootView:add(Button4, AW(25), AH(130));
  
   local text4 = UILabel.new():init('风险票据查询',AW(105),AH(20),self);
  text4.fontHeight = AW(14);
  text4.fontColor = 0x000000;
  text4.align = 0;
  rootView:add(text4,AW(20),AH(205));


 local Button5 = UIButton.new():init(AW(70),AW(70),self,5);
  Button5.bgImage = UIImage.imageName('system/51.png');
  Button5.focusImage = UIImage.imageName('system/52.png');
  rootView:add(Button5, AW(128), AH(130));
  
   local text5 = UILabel.new():init('大额行号',AW(75),AH(20),self);
  text5.fontHeight = AW(14);
  text5.fontColor = 0x000000;
  text5.align = 1;
  rootView:add(text5,AW(125),AH(205));
  
  
   local Button6 = UIButton.new():init(AW(70),AW(70),self,6);
  Button6.bgImage = UIImage.imageName('system/61.png');
  Button6.focusImage = UIImage.imageName('system/62.png');
  rootView:add(Button6, AW(230), AH(130));
  
   local text6 = UILabel.new():init('现贴计算器',AW(75),AH(20),self);
  text6.fontHeight = AW(14);
  text6.fontColor = 0x000000;
  text6.align = 2;
  rootView:add(text6,AW(220),AH(205));
  
  local status = true;
  
  if status then
--假数据
    local aa = MLFile.readFile('res/data/GalleryView.txt');
    local jsonItem = MLNative.json(aa);
    print('aa = ', aa);
    print('假数据 = ', jsonItem);

    if jsonItem and jsonItem.rsp_code == '1001' then

      print('GalleryView 长度 = ', #jsonItem.imageList);


--轮播图数组
       -- 创建轮播图数组
      self.GalleryArray = {};
      -- 创建URL数组
      self.URLArray = {};
      -- 创建title数组
      self.TitleArray = {};

       for i = 1, #jsonItem.imageList do
        -- MLWebImageView:initWebImageView(w,  h, url, nil, viewCtrl, id);
        self.GalleryArray[i] = MLWebImageView.new():initWebImageView(AW(320), AW(160), jsonItem.imageList[i].picAddr, nil, self, 1);
        
        --self.GalleryArray[i] = UIImageView.new():init(UIImage.imageName('11.png'), w, AW(160), self);
                                
        
        table.insert(self.URLArray, i, jsonItem.imageList[i].urlAddr);
        table.insert(self.TitleArray, i, jsonItem.imageList[i].title);
        -- 点击事件
        self.GalleryArray[i].onClick = function()

          HomeViewURL.url = self.URLArray[i];       -- URL
          HomeViewURL.title = self.TitleArray[i];   -- 头部名称

          -- 页面跳转
          local next = HomeViewURL.new();
          self:push(next);

        end
      end
    else
      UIHUD:notify('网络连接失败',2000,self);
    end
  else

    UIHUD:notify('网络连接失败',2000,self);
  
end
   
   
    -- 轮播图
  local mImageFlow = UIGalleryView.new():init(self.GalleryArray, AW(320), AW(160), 1, self);
  
  rootView:add(mImageFlow, AW(0), AH(250));
     

end





--[[
功能   ： controller恢复 代理
参数   ： 无
返回   ： 无
]]
function HomeView:onResume()


end

--[[
功能   ： 监听返回键
参数   ： 无
返回   ： 无
]]
function HomeView:onCtrlPressKeyBack()
  --print("HomeView:onCtrlPressKeyBack()")
  self:pop();
end

--[[
功能   ： controller暂停 代理
参数   ： 无
返回   ： 无
]]
function HomeView:onPause()
--print("HomeView:onPause")
end

--[[
功能   ： controller 摧毁代理
参数   ： 无
返回   ： 无
]]
function HomeView:onDestroy()
--print("HomeView:onDestroy")
end
